﻿
#If Not PocketPC AndAlso Not Smartphone Then
Imports System.Web
#End If

Namespace urlUtils
    Public Module urlUtils

#If Not PocketPC AndAlso Not Smartphone Then
        Public Function xmlizate(ByRef s As String) As String
            Return urlxmlizate(s)
        End Function

        Public Function urlxmlizate(ByRef s As String) As String
            Return htmlencode(s)
        End Function

        Public Function dexmlizate(ByRef s As String) As String
            Return urldexmlizate(s)
        End Function

        Public Function urldexmlizate(ByRef s As String) As String
            Return htmldecode(s)
        End Function

        Public Function htmlencode(ByRef s As String) As String
            s = HttpUtility.HtmlEncode(s)
            Return s
        End Function

        Public Function htmldecode(ByRef s As String) As String
            s = HttpUtility.HtmlDecode(s)
            Return s
        End Function
#End If

        Public Function urlencode(ByRef s As String, Optional ByRef e As System.Text.Encoding = Nothing) As String
#If Not (PocketPC OrElse Smartphone) Then
            If e Is Nothing Then
                e = encoding.utf8
            End If

            s = HttpUtility.UrlEncode(s, e)
            Return s
#Else
            s = System.Uri.EscapeDataString(s)
            Return s
#End If
        End Function

        Public Function urldecode(ByRef s As String, Optional ByRef e As System.Text.Encoding = Nothing) As String
#If Not (PocketPC OrElse Smartphone) Then
            If e Is Nothing Then
                e = encoding.utf8
            End If

            s = HttpUtility.UrlDecode(s, e)
            Return s
#Else
            s = System.Uri.UnescapeDataString(s)
            Return s
#End If
        End Function

        Public Function urlpath2filesystempath(ByRef s As String) As String
            Return strrplc(s, character.leftSlash, character.rightSlash)
        End Function

        Public Function filesystempath2urlpath(ByRef s As String) As String
            Return strrplc(s, character.rightSlash, character.leftSlash)
        End Function

    End Module
End Namespace
